package com.example.yuejian.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.yuejian.Bean.OrderBean;
import com.example.yuejian.R;
import com.example.yuejian.UnitData;
import com.example.yuejian.data.CircleImageView;
import com.squareup.picasso.Picasso;

import java.util.List;


public class OrderAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
    private Context mContext;
    private List<OrderBean.OrderlistBean> mList;
    public LayoutInflater mLayoutInflater;

    public OrderAdapter(Context mContext, List<OrderBean.OrderlistBean> List) {
        this.mContext = mContext;
        this.mList = List;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_my_post, parent, false);
        OrderAdapter.ViewHolder v = new OrderAdapter.ViewHolder(view);

        return v;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final OrderBean.OrderlistBean club = (OrderBean.OrderlistBean) mList.get(position);
        if (null == club)
            return;
        OrderAdapter.ViewHolder viewHolder = (OrderAdapter.ViewHolder) holder;

            viewHolder.name.setText(club.getName());
            viewHolder.number.setText(club.getNumber());
            viewHolder.price.setText(club.getPrice());
            viewHolder.data.setText(club.getData());
            if (!club.getPic().isEmpty()) {
                Picasso.with(mContext).load(UnitData.IMG_URL + club.getPic()).into(viewHolder.img_club);
            }
        }

    

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name,data,number,price;
        CircleImageView img_club;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            number = (TextView) itemView.findViewById(R.id.number);
            data = (TextView) itemView.findViewById(R.id.data);
            price = (TextView) itemView.findViewById(R.id.price);
            img_club = (CircleImageView) itemView.findViewById(R.id.img_club);


        }
    }
}